package com.itheima.homework6;

import java.io.File;

public class Demo6_DirLength {
    public static void main(String[] args) {
        File dir = new File("F:\\歌曲");
        long dirLength = getDirLength(dir);
        System.out.println(dirLength);
    }

    public static long getDirLength(File dir) {
        File[] dirArray = dir.listFiles();
        long len = 0;
        if (dirArray != null) {
            for (File d : dirArray) {
                if (d.isFile()) {
                    len += d.length();
                }else {
                    len += getDirLength(d);
                }
            }
        }
        return len;
    }
}
